package com.xyoto.takeawayBusiness.service.impl;

import com.xyoto.takeawayBusiness.constant.DataBasesOperationResult;
import com.xyoto.takeawayBusiness.enums.CommonEnum;
import com.xyoto.takeawayBusiness.enums.ShoppingEnum;
import com.xyoto.takeawayBusiness.exception.ExceptionUtils;
import com.xyoto.takeawayBusiness.mapper.ShoppingGoodsMapper;
import com.xyoto.takeawayBusiness.service.ShoppingGoodsService;
import com.xyoto.takeawayBusiness.utils.JudgeParamUtils;
import com.xyoto.takeawayBusiness.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName:
 * @Author: 挽风
 * @Date: 2022
 * @Copyright: 2022 by 挽风
 * @Description:
 **/

@Service
@Slf4j
public class ShoppingGoodsServiceImpl implements ShoppingGoodsService {

    @Autowired
    private ShoppingGoodsMapper shoppingGoodsMapper;

    /**
     * 删除商品规格
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result removeGoods(Integer id) {
        JudgeParamUtils.judgeIntegerParam(id);
        Integer flag = shoppingGoodsMapper.removeGoods(id);
        if (flag == DataBasesOperationResult.ERROR) {
            ExceptionUtils.error(ShoppingEnum.DEL_GOODS_FAIL);
        }
        return Result.success();
    }
}
